package src.clientlogic;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;


public class Client {
	static String inetAdress;
	private Socket connectionSocket;
	
	public Client(String inetAdress) {
		super();
		this.inetAdress = inetAdress;
		try {
			this.connectionSocket=new Socket(inetAdress,8080);
		} catch (UnknownHostException e) {
			System.out.println("Unknown Host on client");
		} catch (IOException e) {
			System.out.println("IOException on client in socket creation");
		}
	}

	public static void main(String[] args) {
		try{
			
			Socket s=new Socket(inetAdress,8080);
			final PrintStream ps = new PrintStream(s.getOutputStream(), true);
			ps.print("GET / HTTP/1.0\r\nHost: 127.0.0.1:8080\r\n");
	     
			Scanner scaner=new Scanner(s.getInputStream());
			StringBuilder sb=new StringBuilder();
			while (scaner.hasNext()){
				sb.append(scaner.nextLine());
				sb.append("\n");
			}
		
		System.out.println(sb.toString());
		} catch (IOException e){
			System.out.println("IOException on client");
		}

	}
	public String get(){
		try{
			Socket s=new Socket(inetAdress,8080);
				final PrintStream ps = new PrintStream(s.getOutputStream(), true);
				ps.print("GET / HTTP/1.0\r\nHost: 127.0.0.1:8080\r\n");
		     
				Scanner scaner=new Scanner(s.getInputStream());
				StringBuilder sb=new StringBuilder();
				while (scaner.hasNext()){
					sb.append(scaner.nextLine());
					sb.append("\n");
				}
			
			return sb.toString();
			} catch (IOException e){
				System.out.println("IOException on client");
				return "error";
			}
		}

}
